package com.techsen.tsweb.sys.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.techsen.tsweb.core.service.impl.BaseService;
import com.techsen.tsweb.sys.dao.AclDao;
import com.techsen.tsweb.sys.domain.Acl;
import com.techsen.tsweb.sys.domain.Role;
import com.techsen.tsweb.sys.domain.User;
import com.techsen.tsweb.sys.service.AclService;

@Service
public class AclServiceImpl extends BaseService<Acl, AclDao> implements AclService {

    @Resource @Override
    public void setDao(AclDao dao) {
        this.dao = dao;
    }

    /**
     * 根据用户ID删除ACL集合
     */
    @Override
    public void deleteByUserId(String userId) {
        this.dao.deleteByEntity(new Acl()
            .setPrincipalType(User.class.getSimpleName().toLowerCase())
            .setPrincipalId(userId));
    }

    /**
     * 根据角色ID删除ACL集合
     */
    @Override
    public void deleteByRoleId(String roleId) {
        this.dao.deleteByEntity(new Acl()
            .setPrincipalType(Role.class.getSimpleName().toLowerCase())
            .setPrincipalId(roleId));
    }

}
